﻿using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using Blackbird.Common.Utility;
using Blackbird.Core.Editable.Base;
using Blackbird.Core.Editable.Map;
using Blackbird.Core.Editable.Sprites;

namespace Blackbird.Core.Editable {
    public class EditableModule : BaseEditableEntity {
        public EditableModule() {
            Name = "Untitled";
            SpritePack = new EditableSpritePack();
            MapList = new EditableMapList();
        }

        public EditableSpritePack SpritePack { get; private set; }
        public EditableMapList MapList { get; private set; }

        #region IEditableEntity Members

        public override string TypeName {
            get { return Common.Properties.Resources.EditableModuleTypeFriendlyName; }
        }

        protected override void ReadXmlAttributes(XmlReader reader) {
            Name = SerializationUtility.ReadAttribute(reader, "name", "name");
        }

        protected override void ReadXmlContent(XmlReader reader) {

            MapList.ReadXml(reader);
            SpritePack.ReadXml(reader);
        }

        protected override void WriteXmlAttributes(XmlWriter writer) {
            writer.WriteAttributeString("name", Name);
        }

        protected override void WriteXmlContent(XmlWriter writer) {

            MapList.WriteXml(writer);
            SpritePack.WriteXml(writer);
        }
        #endregion
    }
}